#include "plugin_warn.h"

/**
 * @brief plugin_warn::initUi 初始化ui
 */
void plugin_warn::initUi()
{
    static bool initFlag = true;
    if (initFlag)
    {
        initFlag = false;
        plugin_warn_ui->verticalLayout->addWidget(&mWarnTable);
        // 信号绑定
        QObject::connect(&mWarnTable, &warn_table::signalToForward,
                         this, [this](const QString &arg) { // 改用const引用
                             emit messageFromPlugin(pluginName(), arg);
                         });
    }
}

/**
 * @brief sendMessageToPlugin 接收来自其他任务的信息
 * @param msg
 */
void plugin_warn::sendMessageToPlugin(const QString &msg)
{
    initUi();
    processJsonCommand(msg);
}
/**
 * @brief plugin_warn::processJsonCommand 解析json字符串并将内容赋值到m_dataBlockMap
 * @param jsonStr
 */
void plugin_warn::processJsonCommand(const QString &jsonStr)
{
    QString err;
    if (false == mWarnTable.processJsonCommand(jsonStr, &err))
    {
        emit messageFromPlugin(pluginName(), err);
    }
}
